#include <iostream>
using namespace std;

class Person 
{
public:
    Person(){
        cout<< "Person()"<<endl;
    }
    virtual ~Person(){
        cout<< "~Person()"<<endl;
    }
    virtual void eat() = 0;
};

class Student: public Person
{
public:
    Student(){
        cout<< "Student()"<<endl;
    }
    virtual ~Student(){
        cout << "~Student()"<<endl;
    }
    virtual void eat(){
        cout <<"Student::eat()"<<endl;
    }
    void study(){
        cout << "Student::study()" << endl;
    }  
};
class Teacher: public Person
{
public:
    Teacher(){
        cout<< "Teacher()"<<endl;
    }
    virtual ~Teacher(){
        cout << "~Teacher()"<<endl;
    }
    virtual void eat(){
        cout <<"Teacher::eat()"<<endl;
    }
    void teach(){
        cout << "Teacher::teach()" << endl;
    }  
};
void doSomething(Person *p)
{
    p->eat();
    if(typeid(*p) == typeid(Student)) {
        Student *stu = dynamic_cast<Student*>(p);
        stu->study();
    }
    if(typeid(*p) == typeid(Teacher)) {
        Teacher *tea = dynamic_cast<Teacher*>(p);
        tea->teach();
    }
}
int main()
{
    Student s;
    Teacher t;
    doSomething(&s);
    doSomething(&t);
    return 0; 
}